package com.demo2do.fms.admin.entity.search.data;

import java.util.Map;

import com.demo2do.core.persistence.support.QueryBuilder;
import com.demo2do.core.persistence.support.QueryFilter;
import com.demo2do.core.persistence.support.QueryOrder;

/**
 * 
 * @author Chang Liu
 */

public class CitySearch implements QueryBuilder {

    /** 城市名称 */
	private String cityName;
	
	/** 省份名称 */
	private String provinceName;
	
	private QueryFilter filter;
	
	private QueryOrder order;
	
	/**
	 * The default constructor
	 */
	public CitySearch() {
		order = new QueryOrder().add("code", "ASC");
	}
	
	/*
	 * (non-Javadoc)
	 * @see com.demo2do.core.persistence.support.QueryBuilder#getPreparedFilter(boolean)
	 */
	public QueryFilter getPreparedFilter(boolean refresh) {
	    
		if (filter == null || refresh) {
		    
			filter = new QueryFilter().addLike("name", cityName)
					                  .addLike("provinceName", provinceName);
			
		}
		
		return filter;
	}

	/*
	 * (non-Javadoc)
	 * @see com.demo2do.core.persistence.support.QueryBuilder#buildSentenceTemplate()
	 */
	public String buildSentenceTemplate() {
		String sentence = "FROM City WHERE disabled = false" + getPreparedFilter(false).clauseSentence() + order.sentence();
		return sentence;
	}

	/*
	 * (non-Javadoc)
	 * @see com.demo2do.core.persistence.support.QueryBuilder#buildParameters()
	 */
	public Map<String, Object> buildParameters() {
		return getPreparedFilter(false).parameters();
	}
	
	/*
	 * (non-Javadoc)
	 * @see com.demo2do.core.persistence.support.QueryBuilder#getOrder()
	 */
	public QueryOrder getOrder() {
		return order;
	}
	
	/**
	 * 
	 * @return
	 */
	public QueryFilter getFilter(){
		return getPreparedFilter(false);
	}

	
	/**
	 * @return the cityName
	 */
	public String getCityName() {
		return cityName;
	}

	/**
	 * @return the provinceName
	 */
	public String getProvinceName() {
		return provinceName;
	}

	/**
	 * @param cityName the cityName to set
	 */
	public void setCityName(String cityName) {
		this.cityName = cityName;
	}

	/**
	 * @param provinceName the provinceName to set
	 */
	public void setProvinceName(String provinceName) {
		this.provinceName = provinceName;
	}

}
